package com.mysdnu.mysdnu_android;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class WelcomeActivity extends Activity implements Runnable {
	private SharedPreferences shared;
	private Context context;
	private Handler handler = new Handler() {
		private Intent intent;

		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 0:
				intent = new Intent();
				String user = shared.getString("user", "");
				String pass = shared.getString("pass", "");
				if (shared != null) {
					if (user.equals("") || pass.equals("")) {
						intent.setClass(context, LoginActivity.class);
					} else {
						intent.setClass(context, MainActivity.class);
					}
					startActivity(intent);
				}
				finish();
				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		context = this;
		shared = getSharedPreferences("userInfo", MODE_PRIVATE);
		new Thread(this).start();
		Window w;
		Handler hand;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		handler.sendEmptyMessage(0);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (handler != null) {
			handler.removeCallbacks(this);
			handler = null;
		}
	}
}
